package com.gxar.marketdelivery.interfaces.assembler;

import com.gxar.marketdelivery.infra.dao.entity.DeliveryMaterialEntity;
import com.gxar.marketdelivery.infra.dao.entity.DeliveryResSlotEntity;
import com.gxar.marketdelivery.interfaces.web.result.DeliveryResSlotResult;
import com.gxar.marketdelivery.shared.model.DeliveryResSlotModel;
import com.gxar.marketdelivery.shared.utils.AssemblerUtils2;
import com.gxar.marketdelivery.shared.utils.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author nice
 * @version 1.0
 * @created 2023/7/21.
 */
public class DeliveryResSlotConverter {

    public static DeliveryResSlotResult convertToResult(DeliveryResSlotEntity entity) {
        return convertToResult(entity, null);
    }

    public static DeliveryResSlotResult convertToResult(DeliveryResSlotEntity entity,
            DeliveryMaterialEntity materialEntity) {
        DeliveryResSlotResult result = new DeliveryResSlotResult();
        AssemblerUtils2.assemble(entity, result);
        result.setId(String.valueOf(entity.getId()));
        if (materialEntity != null) {
            result.setMaterialModel(DeliveryMaterialConverter.convertToModel(materialEntity));
        }

        return result;
    }

    public static List<DeliveryResSlotResult> convertToResultList(List<DeliveryResSlotEntity> entities) {
        if (CollectionUtils.isEmpty(entities)) {
            return Collections.emptyList();
        }

        return entities.stream().map(DeliveryResSlotConverter::convertToResult).collect(Collectors.toList());
    }

    public static DeliveryResSlotModel convertToModel(DeliveryResSlotEntity entity,
            DeliveryMaterialEntity materialEntity, Map<Long, DeliveryMaterialEntity> abtestMaterialMap) {
        DeliveryResSlotModel model = new DeliveryResSlotModel();
        AssemblerUtils2.assemble(entity, model);
        model.setMaterialModel(DeliveryMaterialConverter.convertToModel(materialEntity));
        return model;
    }
}
